package model;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class RentalOrder {
    private String id;
    private Customer customer;
    private Car car;
    private LocalDateTime startTime;
    private int rentDays;
    private double carRentPrice;
    private double deliveryFee;
    private double totalPrice;
    private boolean isReturned;
    private LocalDateTime returnTime;

    public void completeReturn(){
        this.isReturned = true;
        this.returnTime = LocalDateTime.now();
    }

    public RentalOrder() {
    }

    public RentalOrder(String id, Customer customer, Car car, LocalDateTime startTime, int rentDays, double carRentPrice, double deliveryFee, double totalPrice, boolean isReturned, LocalDateTime returnTime) {
        this.id = id;
        this.customer = customer;
        this.car = car;
        this.startTime = LocalDateTime.now();
        this.rentDays = rentDays;
        this.carRentPrice = carRentPrice;
        this.deliveryFee = deliveryFee;
        this.totalPrice = totalPrice;
        this.isReturned = false;
        this.returnTime =  null;
    }

    /**
     * 获取
     * @return id
     */
    public String getId() {
        return id;
    }

    /**
     * 设置
     * @param id
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     * 获取
     * @return customer
     */
    public Customer getCustomer() {
        return customer;
    }

    /**
     * 设置
     * @param customer
     */
    public void setCustomer(Customer customer) {
        this.customer = customer;
    }

    /**
     * 获取
     * @return car
     */
    public Car getCar() {
        return car;
    }

    /**
     * 设置
     * @param car
     */
    public void setCar(Car car) {
        this.car = car;
    }

    /**
     * 获取
     * @return startTime
     */
    public LocalDateTime getStartTime() {
        return startTime;
    }

    /**
     * 设置
     * @param startTime
     */
    public void setStartTime(LocalDateTime startTime) {
        this.startTime = startTime;
    }

    /**
     * 获取
     * @return rentDays
     */
    public int getRentDays() {
        return rentDays;
    }

    /**
     * 设置
     * @param rentDays
     */
    public void setRentDays(int rentDays) {
        this.rentDays = rentDays;
    }

    /**
     * 获取
     * @return carRentPrice
     */
    public double getCarRentPrice() {
        return carRentPrice;
    }

    /**
     * 设置
     * @param carRentPrice
     */
    public void setCarRentPrice(double carRentPrice) {
        this.carRentPrice = carRentPrice;
    }

    /**
     * 获取
     * @return deliveryFee
     */
    public double getDeliveryFee() {
        return deliveryFee;
    }

    /**
     * 设置
     * @param deliveryFee
     */
    public void setDeliveryFee(double deliveryFee) {
        this.deliveryFee = deliveryFee;
    }
    /**
     * 获取
     * @return totalPrice
     */

    public double getTotalPrice() {
        return totalPrice;
    }
    /**
     * 设置
     * @param totalPrice
     */
    public void setTotalPrice(double totalPrice) {
        this.totalPrice = totalPrice;
    }

    /**
     * 获取
     * @return isReturned
     */
    public boolean isIsReturned() {
        return isReturned;
    }

    /**
     * 设置
     * @param isReturned
     */
    public void setIsReturned(boolean isReturned) {
        this.isReturned = isReturned;
    }

    /**
     * 获取
     * @return returnTime
     */
    public LocalDateTime getReturnTime() {
        return returnTime;
    }

    /**
     * 设置
     * @param returnTime
     */
    public void setReturnTime(LocalDateTime returnTime) {
        this.returnTime = returnTime;
    }

    public String toString() {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm");
        StringBuilder sb = new StringBuilder();
        sb.append("订单ID: ").append(id).append("\n");
        sb.append("客户信息: ").append(customer).append("\n");
        sb.append("车辆信息: ").append(car.getCarInfo()).append("\n");
        sb.append("租赁开始时间: ").append(startTime.format(formatter)).append("\n");
        sb.append("租赁天数: ").append(rentDays).append("天\n");
        sb.append("费用明细: 车辆租金 ").append(carRentPrice).append("元 + 上门费 ").append(deliveryFee).append("元\n");
        sb.append("总租金: ").append(totalPrice).append("元\n");
        sb.append("状态: ").append(isReturned ? "已归还" : "未归还").append("\n");
        if (isReturned) {
            sb.append("归还时间: ").append(returnTime.format(formatter)).append("\n");
        }
        return sb.toString();
    }
}
